#include    "unp.h"
  2
  3 int
  4 main(int argc, char **argv)
  5 {
  6     int                 sockfd, n;
  7     char                recvline[MAXLINE + 1];
  8     struct sockaddr_in  servaddr;
  9
 10     if (argc != 2)
 11         err_quit("usage: a.out <IPaddress>");
 12
 13     if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
 14         err_sys("socket error");
 15
 16     bzero(&servaddr, sizeof(servaddr));
 17     servaddr.sin_family = AF_INET;
 18     servaddr.sin_port   = htons(13);    /* daytime server */
 19     if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0)
 20         err_quit("inet_pton error for %s", argv[1]);
 21
 22     if (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0)
 23         err_sys("connect error");
 24
 25     while ( (n = read(sockfd, recvline, MAXLINE)) > 0) {
 26         recvline[n] = 0;    /* null terminate */
 27         if (fputs(recvline, stdout) == EOF)
 28             err_sys("fputs error");
 29     }                                                                                                               
 30     if (n < 0)
 31         err_sys("read error");
 32         
 33     exit(0);
 34 }
